package protocol

import (
	"gitee.com/crack007/goose"
	"gitee.com/crack007/goose/core/server"
	"gitee.com/crack007/udp-penetrate/src/common/constant"
	"net"
)

type MessageProtocol struct {
	Msg string
}

func NewMessageProtocol() *MessageProtocol {
	return &MessageProtocol{}
}

func (p *MessageProtocol) Code() uint32 {
	return constant.CMD_MESSAGE_REQ
}

// client端执行
func (p *MessageProtocol) Process(session *server.Session, clientConn *net.UDPConn) IProtocol {
	goose.GetLogger().Info("receive msg-> %s", p.Msg)
	heartbeatProtocol := NewHeartbeatProtocol()
	heartbeatProtocol.Finish = 1
	heartbeatProtocol.Body = "resp:" + p.Msg
	return heartbeatProtocol
}

func (p *MessageProtocol) Marshall() []byte {
	return []byte(p.Msg)
}

func (p *MessageProtocol) UnMarshall(data []byte) {
	p.Msg = string(data)
}
